<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
  <!-- Google tag (gtag.js) -->
  <script async src="https://www.googletagmanager.com/gtag/js?id=G-0ZJQN9ZQ47"></script>
  <script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-0ZJQN9ZQ47');
  </script>
  <meta charset="utf-8">
  <title>Jekyll、MSYS2、Vibora 及在 Windows 下用 Linux &mdash; 褪色的抽象</title>
  <meta name="author" content="Kaffa">






  <!-- http://t.co/dKP3o1e -->
  <meta name="HandheldFriendly" content="True">
  <meta name="MobileOptimized" content="320">
  <meta name="viewport" content="width=device-width, initial-scale=1">


    <link href="./favicon.ico" rel="icon">

  <link href="./theme/css/main.css" media="screen, projection"
        rel="stylesheet" type="text/css">
  <!--
  <link href="//fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic"
        rel="stylesheet" type="text/css">
  <link href="//fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic"
        rel="stylesheet" type="text/css">
  -->
</head>

<body>
  <header role="banner"><hgroup>
  <h1><a href="./"><span style="color:#52A2C6">褪</span>
<span style="color:#6791BC">色</span>
<span style="color:#7C80B2">的</span>
<span style="color:#916FA8">抽</span>
<span style="color:#A65E9E">象</span></a></h1>
    <h2>kaffa's blog</h2>
</hgroup></header>
  <nav role="navigation"><ul class="subscription" data-subscription="rss">
</ul>


<ul class="main-navigation">
    <li><a href="/">首页</a></li>
    <li><a href="/category/sui-bi.html">随笔</a></li>
    <li><a href="/category/yue-du.html">阅读</a></li>
    <li><a href="/category/ren-wen.html">人文</a></li>
    <li><a href="/category/zi-ran.html">自然</a></li>
    <li><a href="/category/ri-zhi.html">日志</a></li>
</ul></nav>
  <div id="main">
    <div id="content" class="bronze">
<div>
  <article class="hentry" role="article">
<header>
      <h1 class="entry-title">Jekyll、MSYS2、Vibora 及在 Windows 下用 Linux</h1>
    <p class="meta">
<time datetime="2018-08-14T12:00:00+08:00" pubdate>2018-08-14 周二</time>    </p>
</header>

  <div class="entry-content"><div class="section" id="section-1">
<h2>故事</h2>
<p>故事开始于我需要在 Windows 下用 Jekyll 转化一篇 Markdown 的博文，于是在 Windows 下安装了 Jekyll，其中涉及一些 MSYS2 的安装坑。
接下来想到 MSYS2 其实可以解决 Vibora 的问题，于是将这两个过程中的难点记录一下，再谈谈在 Windows 下使用 Linux 的话题。</p>
<p>本文旨在为正使用 Windows 同时又想使用 Linux 功能的人列举一些可能的途径，本文适用于对 Windows 和 Linux 具备一定了解的人。
另有计划写 Windows、macOS、Linux 操作系统比较的博文，但本文的范围不涉及比较。</p>
</div>
<div class="section" id="widnows-jekyll">
<h2>Widnows 下用 Jekyll</h2>
<p>Jekyll 依赖于 Ruby Runtime 和一些 Gem 包，而 Ruby Runtime 在 Windows 下推荐用于 <a class="reference external" href="https://rubyinstaller.org/">RubyInstaller</a>，
某些 Gem 包需要本地编译，官方推荐 <a class="reference external" href="http://www.msys2.org/">MSYS2</a> 安装 Windows 上的编译工具链。
因为众所周知的原因，国内安装这些软件时也会遇到一些问题。下面叙述步骤并给予问题的解决办法。</p>
<div class="section" id="ruby">
<h3>安装 Ruby</h3>
<p>运行下载好的 RubyInstaller，基于少一层目录的原因，建议直接安装在根目录下，例如 <tt class="docutils literal"><span class="pre">C:\Ruby25\</span></tt>，并将此目录加入安装目录到 PATH。在最后点击结束按钮后，会提示安装 MSYS2，它用来编译 Ruby 本地包，官方说它的下载由一个全球 CDN 提供，但它在国内的访问真是无力吐槽。</p>
<p>也许你等待龟速网络很久可以将 MSYS2 安装成功，也许你会遭遇反复失败，不知如何是好。但如果你需要使用 Jekyll，而它使用了本地二进制包，那么这个问题是无法跳过的。</p>
</div>
<div class="section" id="msys2">
<h3>安装 MSYS2 的小技巧</h3>
<p>如果你跳过了 MSYS2 安装，那么在后续的 gem install 时，会提示：</p>
<div class="highlight"><pre><span></span>MSYS2 could not be found. Please run &#39;ridk install&#39; or download and install MSYS2 manually from https://msys2.github.io/
</pre></div>
<p>当你执行 <tt class="docutils literal">ridk install</tt> 时，会显示下载 <a class="reference external" href="http://repo.msys2.org/distrib/x86_64/msys2-x86_64-20180531.exe">http://repo.msys2.org/distrib/x86_64/msys2-x86_64-20180531.exe</a> 失败，我的解决办法是用迅雷下载 <tt class="docutils literal"><span class="pre">msys2-x86_64-20180531.exe</span></tt>，并用 IIS 或 Apache 等服务器，在本地配置一个站点下载，这样做需要管理员权限修改 <tt class="docutils literal"><span class="pre">C:\Windows\System32\drivers\etc\hosts</span></tt> 文件，临时加入一行配置：</p>
<div class="highlight"><pre><span></span>127.0.0.1    repo.msys2.org
</pre></div>
<p>此时确保访问 <a class="reference external" href="http://127.0.0.1/distrib/x86_64/msys2-x86_64-20180531.exe">http://127.0.0.1/distrib/x86_64/msys2-x86_64-20180531.exe</a> 时可以正常下载。那么再次运行 <tt class="docutils literal">ridk install</tt> 时，就会通过本机下载了。</p>
<p>然后，当 <tt class="docutils literal"><span class="pre">msys2-x86_64-20180531.exe</span></tt> 下载完毕时，需要及时把上述 hosts 配置行删除，因为本机并没有 <tt class="docutils literal">repo.msys2.org</tt> 站点下的其他文件。</p>
</div>
<div class="section" id="msys2-1">
<h3>配置 MSYS2 镜像地址</h3>
<p>同时，为了 MSYS2 其他包方便下载，建议配置国内镜像，分别修改下面三个文件，在配置的最上加入 清华大学 与 中科大镜像地址</p>
<p><tt class="docutils literal"><span class="pre">C:\msys64\etc\pacman.d\mirrorlist.mingw64</span></tt></p>
<div class="highlight"><pre><span></span>##
## 64-bit Mingw-w64 repository mirrorlist
##
## 清华大学软件镜像
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64/
## 中科大镜像
Server = http://mirrors.ustc.edu.cn/msys2/mingw/x86_64/
</pre></div>
<p><tt class="docutils literal"><span class="pre">C:\msys64\etc\pacman.d\mirrorlist.mingw32</span></tt></p>
<div class="highlight"><pre><span></span>##
## 32-bit Mingw-w64 repository mirrorlist
##
## 清华大学软件镜像
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686/
## 中科大镜像
Server = http://mirrors.ustc.edu.cn/msys2/mingw/i686/
</pre></div>
<p><tt class="docutils literal"><span class="pre">C:\msys64\etc\pacman.d\mirrorlist.msys</span></tt></p>
<div class="highlight"><pre><span></span>##
## MSYS2 repository mirrorlist
##
## 清华大学软件镜像
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch/
## 中科大镜像
Server = http://mirrors.ustc.edu.cn/msys2/msys/$arch/
</pre></div>
<p>如果你及时删除了 hosts 文件中的配置行，那么 NSYS2 即可以顺利完成安装。</p>
</div>
<div class="section" id="msys2-2">
<h3>测试 MSYS2 安装是否成功</h3>
<p>可以再次运行 <tt class="docutils literal">ridk install</tt>，命令行会打开</p>
<div class="highlight"><pre><span></span>RubyInstaller2 for Windows

1 - MSYS2 base installation
2 - MSYS2 system update
3 - MSYS2 and MINGW development toolchain
</pre></div>
<p>试试 1、2、3 三个选项，如果全部没有可更新项时，就证明 MSYS2 安装已经成功了。</p>
</div>
<div class="section" id="gem">
<h3>配置 Gem 镜像地址</h3>
<p>对于有价值的开源技术，国内一般都进行了镜像，一般都建议直接使用国内镜像地址。运行下面命令配置镜像</p>
<div class="highlight"><pre><span></span>gem sources –r https://rubygems.org/
gem sources -a https://ruby.taobao.org/
</pre></div>
<p>运行下面命令查看，并更新</p>
<div class="highlight"><pre><span></span>gem sources -l
gem update
</pre></div>
</div>
<div class="section" id="jekyll">
<h3>安装 Jekyll</h3>
<p>下面是官方网站优雅的几行介绍</p>
<div class="highlight"><pre><span></span>~ $ gem install bundler jekyll
~ $ jekyll new my-awesome-site
~ $ cd my-awesome-site
~/my-awesome-site $ bundle exec jekyll serve
# =<span class="p">&gt;</span> Now browse to http://localhost:4000
</pre></div>
<p>有了上面步骤的铺垫，至此，Jekyll 可以优雅的运行了。</p>
</div>
<div class="section" id="ruby-1">
<h3>关于 Ruby 的感叹</h3>
<p>十年前，曾在 Ruby 语言通过 Web 2.0 的需求爆发时，借 Web 敏捷框架 Rails 大红大紫了解过它，对这些年一直没有再有机会使用，如果没有 Rails，Ruby 就不会红，定位于 Python 和 Perl 之间，如今它也许会有所发展，但综合来看，都会逐渐变成先前使用了 RoR 公司的技术遗产，市场上 Ruby 的技术人员也会越来越少，加上它本身并未和现在大前端、移动互联网、大数据、云计算、人工智能、VR等任何一个热点沾边，也不具备后端编译语言的规模成本优势，从系统论视角思考，没有生态，就会走向低谷，但在它擅长的 Web 领域内，还是一种有智慧的解决方案。</p>
<p>相比来说，经常能先于时代的 Python 的好运气并不是偶然，因为重视科研领域，它借着大数据分析和人工智能一飞冲天，如今生态广阔的 Python，相比来说就有着更稳固的护城河，这种就好比持续增长的公司拥有的竞争优势一样，更值得长期看好。所以，下面就说说 Python Web Framework：Vibora</p>
</div>
</div>
<div class="section" id="widnows-vibora">
<h2>Widnows 下用 Vibora</h2>
<p>Vibora 性能闪瞎眼，为了不让 MSYS2 环境浪费，于是尝试是否可以通过 MSYS2 将它运行起来。</p>
<div class="section" id="msys2-python3">
<h3>MSYS2 安装 python3</h3>
<p>首先，打开 MSYS2 运行 python 或 python3，提示</p>
<div class="highlight"><pre><span></span>-bash: python: 未找到命令
-bash: python3: 未找到命令
</pre></div>
<p>于是我们需要在 MSYS2 中添加软件包，请出 pacman，它移植于著名 LFS ———— Arch Linux 发行版</p>
<p>首先，安装一些依赖和编译工具</p>
<div class="highlight"><pre><span></span>pacman --needed -Sy bash pacman pacman-mirrors msys2-runtime
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb mingw-w64-x86_64-make tmux zsh git mingw64/mingw-w64-x86_64-cmake winpty
pacman -S mingw-w64-x86_64-python3-bsddb3 mingw-w64-x86_64-gexiv2 mingw-w64-x86_64-ghostscript mingw-w64-x86_64-python3-cairo mingw-w64-x86_64-python3-gobject mingw-w64-x86_64-python3-icu mingw-w64-x86_64-iso-codes mingw-w64-x86_64-hunspell mingw-w64-x86_64-hunspell-en mingw-w64-x86_64-enchant
</pre></div>
<p>接下来安装 python3 和 pip3</p>
<div class="highlight"><pre><span></span>pacman -S mingw-w64-x86_64-python3
pacman -S python3-pip
</pre></div>
<p>此时 python3 和 pip3 已经安装，顺便把 pip3 升个级，最近它的版本号也像 Chrome 一样一发不可收拾。</p>
<div class="highlight"><pre><span></span>pip3 install --upgrade pip
</pre></div>
</div>
<div class="section" id="msys2-vibora">
<h3>MSYS2 安装 vibora</h3>
<p>再安装 vibora</p>
<div class="highlight"><pre><span></span>pip3 install vibora
</pre></div>
<p>提示错误：</p>
<div class="highlight"><pre><span></span>Running setup.py install for vibora ... error
Complete output from command /usr/bin/python3 -u -c <span class="s2">&quot;import setuptools, toke</span>
nize;__file__=&#39;/tmp/pip-install-rawskw89/vibora/setup.py&#39;;f=getattr(tokenize, &#39;o
pen&#39;, open)(__file__);code=f.read().replace(&#39;\r\n&#39;, &#39;\n&#39;);f.close();exec(compile
<span class="p">(</span>code, __file__, &#39;exec&#39;<span class="p">)</span>)<span class="s2">&quot; install --record /tmp/pip-record-9rnpdvhe/install-rec</span>
ord.txt --single-version-externally-managed --compile:

...

unable to execute &#39;x86_64-pc-msys-gcc&#39;: No such file or directory
error: command &#39;x86_64-pc-msys-gcc&#39; failed with exit status 1

...

Command <span class="s2">&quot;/usr/bin/python3 -u -c &quot;</span>import setuptools, tokenize;__file__=&#39;/tmp/pip-
install-rawskw89/vibora/setup.py&#39;;f=getattr(tokenize, &#39;open&#39;, open)(__file__);co
de=f.read().replace(&#39;\r\n&#39;, &#39;\n&#39;);f.close();exec(compile(code, __file__, &#39;exec&#39;)
)<span class="s2">&quot; install --record /tmp/pip-record-9rnpdvhe/install-record.txt --single-version</span>
-externally-managed --compile<span class="s2">&quot; failed with error code 1 in /tmp/pip-install-raws</span>
kw89/vibora/
</pre></div>
<p>想来原因是 Vibora 依赖本地二进制程序进行异步通信。</p>
<p>再安装 x86_64-pc-msys-gcc</p>
<div class="highlight"><pre><span></span>pacman -S gcc
</pre></div>
<p>之后，再次运行 <tt class="docutils literal">pip3 install vibora</tt>，提示</p>
<div class="highlight"><pre><span></span>In file included from vibora/parsers/parser.c:4:0:
/usr/include/python3.6m/Python.h:39:10: 致命错误：crypt.h：No such file or d
irectory
 #include <span class="p">&lt;</span>crypt.h&gt;
          <span class="se">^~</span>~~~~~~~
编译中断。
error: command &#39;x86_64-pc-msys-gcc&#39; failed with exit status 1

----------------------------------------
Command <span class="s2">&quot;/usr/bin/python3 -u -c &quot;</span>import setuptools, tokenize;__file__=&#39;/tmp/pip-install-t22lx1u7/vibora/setup.py&#39;;f=getattr(tokenize, &#39;open&#39;, open)(__file__);code=f.read().replace(&#39;\r\n&#39;, &#39;\n&#39;);f.close();exec(compile(code, __file__, &#39;exec&#39;))<span class="s2">&quot; install --record /tmp/pip-record-f8i8_k06/install-record.txt --single-version-externally-managed --compile&quot;</span> failed with error code 1 in /tmp/pip-install-t22lx1u7/vibora/
</pre></div>
<p>StackOverflow 大法好，提示缺少的 头文件 crypt.h 在 libcrypt-devel 包中，于是再安装 x86_64-pc-msys-gcc</p>
<div class="highlight"><pre><span></span>pacman -S libcrypt-devel
</pre></div>
<p>第三次运行  <tt class="docutils literal">pip3 install vibora</tt></p>
<div class="highlight"><pre><span></span>$ pip3 install vibora
Collecting vibora
Using cached https://files.pythonhosted.org/packages/1c/db/c42998b106b89d67ce0                                            fe256320454ca224e4d3d05f56dd518514a5b738c/vibora-0.0.6.tar.gz
Requirement already satisfied: pendulum in /usr/lib/python3.6/site-packages (from vibora) (2.0.3)
Requirement already satisfied: python-dateutil<span class="p">&lt;</span>3.0,<span class="p">&gt;</span>=2.6 in /usr/lib/python3.6/site-packages (from pendulum-<span class="p">&gt;</span>vibora) (2.7.3)
Requirement already satisfied: pytzdata<span class="p">&gt;</span>=2018.3 in /usr/lib/python3.6/site-packages (from pendulum-<span class="p">&gt;</span>vibora) (2018.5)
Requirement already satisfied: six<span class="p">&gt;</span>=1.5 in /usr/lib/python3.6/site-packages (from python-dateutil<span class="p">&lt;</span>3.0,<span class="p">&gt;</span>=2.6-<span class="p">&gt;</span>pendulum-<span class="p">&gt;</span>vibora) (1.10.0)
Installing collected packages: vibora
Running setup.py install for vibora ... done
Successfully installed vibora-0.0.6
</pre></div>
<p>我的天，成功了！于是试了试官方 hello-world.py</p>
</div>
<div class="section" id="vibora-hello-world">
<h3>运行 vibora hello world</h3>
<div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">vibora</span> <span class="kn">import</span> <span class="n">Vibora</span><span class="p">,</span> <span class="n">Request</span>
<span class="kn">from</span> <span class="nn">vibora.responses</span> <span class="kn">import</span> <span class="n">JsonResponse</span>

<span class="n">app</span> <span class="o">=</span> <span class="n">Vibora</span><span class="p">()</span>

<span class="nd">@app</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
<span class="k">async</span> <span class="k">def</span> <span class="nf">home</span><span class="p">(</span><span class="n">request</span><span class="p">:</span> <span class="n">Request</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">JsonResponse</span><span class="p">({</span><span class="s1">&#39;hello&#39;</span><span class="p">:</span> <span class="s1">&#39;world&#39;</span><span class="p">})</span>

<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">app</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">debug</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">host</span><span class="o">=</span><span class="s1">&#39;0.0.0.0&#39;</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">8000</span><span class="p">)</span>
</pre></div>
<p>提示：</p>
<div class="highlight"><pre><span></span>xxx@yyyy MSYS /d/code/vibora
$ python hello-world.py
Traceback (most recent call last):
File <span class="s2">&quot;hello-world.py&quot;</span>, line 1, in <span class="p">&lt;</span>module&gt;
    from vibora import Vibora, Request
File <span class="s2">&quot;/usr/lib/python3.6/site-packages/vibora/__init__.py&quot;</span>, line 7, in <span class="p">&lt;</span>module&gt;
    from .server import *
File <span class="s2">&quot;/usr/lib/python3.6/site-packages/vibora/server.py&quot;</span>, line 11, in <span class="p">&lt;</span>module&gt;
    from .workers.handler import RequestHandler
File <span class="s2">&quot;/usr/lib/python3.6/site-packages/vibora/workers/handler.py&quot;</span>, line 3, in <span class="p">&lt;</span>module&gt;
    from socket import IPPROTO_TCP, TCP_NODELAY, SO_REUSEADDR, SOL_SOCKET, SO_REUSEPORT, socket
ImportError: cannot import name &#39;SO_REUSEPORT&#39;
</pre></div>
<p>google 错误提示，居然来到了 <a class="reference external" href="https://github.com/vibora-io/vibora/issues/106">vibora-issues-106</a>，状态是关闭的，作者 &#64;frnkvieira 说 &#64;zzeric 已经修复，他已合入最新版，下面又有人要求打开这个 issues，说经过测试依然存在。</p>
<p>&#64;zzeric_ 的解决办法是升级到 python 3.7.0，我个人认为这并非一个好的办法。
&#64;danieldaeschle_ 的解决办法是 <a class="reference external" href="https://github.com/vibora-io/vibora/pull/157">vibora-pull-157</a> ，不过作者并未接受。</p>
<p>我暂时采用了 <a class="reference external" href="https://github.com/danieldaeschle">danieldaeschle</a> 的方法修改，再次运行，提示：</p>
<div class="highlight"><pre><span></span>OSError: [Errno 112] Address already in use
</pre></div>
<p>不过，此时浏览器打开 <a class="reference external" href="http://localhost:8000">http://localhost:8000</a> 已经可以正常显示:</p>
<pre class="literal-block">
{'hello': 'world'}
</pre>
<p>本文的第三部分，剩下的就是作个总结。</p>
</div>
</div>
<div class="section" id="windows-linux">
<h2>Windows 下用 Linux 的途径</h2>
<ul class="simple">
<li><dl class="first docutils">
<dt>虚拟机</dt>
<dd>虚拟机是在物理宿主机上虚拟一台机器，再将 Linux 安装进去。Windows 平台的虚拟机软件也有不少选择，而且微软也内置了一种虚拟机 Hyper-V</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>类Linux / POSIX API 方案</dt>
<dd>这类方案是在 Windows 核心上实现一种 类Linux / POSIX 标准的中间翻译层，要么对接到 Windows 原生动态链接库，要么对接到自带的库。</dd>
</dl>
</li>
<li><dl class="first docutils">
<dt>Windows Subsystem for Linux</dt>
<dd>这是基于市场博弈和市场的发展，微软官方基于 Hyper-V 给出了一个解决方案，这个方案可以从微软商店中下载 Linux，目前官方支持 5 种比较常见的发行版。</dd>
</dl>
</li>
</ul>
<p>下面是我的一些理解</p>
<div class="section" id="virtualbox">
<h3><a class="reference external" href="https://www.virtualbox.org/">VirtualBox</a></h3>
<p>在普通需求上，这是我最愿意使用的一种便携方案，比如国内银行的 usb key 只支持 Windows 时，使用虚拟机也是挺好的，适合个人。</p>
</div>
<div class="section" id="vmware">
<h3><a class="reference external" href="https://www.vmware.com/">VMWare</a></h3>
<p>他们具备成熟的生产环境商业方案，但其实更适合开发环境和测试环境构建一套安全、灵活、可扩展的系统环境。但现在虚拟化的趋势中有所过气，XEN 算是 Linux 上对标的方案。但他们家显卡驱动实在不行。</p>
</div>
<div class="section" id="hyper-v">
<h3><a class="reference external" href="https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v">Hyper-V</a></h3>
<p>在虚拟微软自家系统旧版本时，这个是最佳方案，一些微软自家新技术，也是以此虚拟机发布的。</p>
</div>
<div class="section" id="docker">
<h3><a class="reference external" href="https://www.docker.com/">Docker</a></h3>
<p>它不是虚拟机，但是目前很不错的容器虚拟化技术，但它需要 Widnows Pro 版本以上，且不能与 VirtualBox 和 VMWare 及一些 Android 模拟器共存。</p>
</div>
<div class="section" id="cygwin-mingw">
<h3><a class="reference external" href="https://www.cygwin.com/">Cygwin</a> &amp; <a class="reference external" href="http://www.mingw.org/">MinGW</a></h3>
<p>Cygwin 通过动态链接库 cygwin1.dll，提供一个 POSIX API 子集，编译出 Linux 下的程序通过这个库对接 Windows 底层动态链接库。</p>
<p>MinGW 是 GCC 在 Windows 的实现，通过编译器，把诸如 Linux 系统调用 如 fork 翻译成 Windows API 如 CreateProcess 这样。这种没有引入运行时的中间层，会比 Cygwin 更紧凑。</p>
<p>通俗的说 Cygwin 属于运行时适配，MinGW 属于编译时转化，从技术纯粹来说，我更喜欢 MinGW，但对于绝大多数小的程序，Cygwin 虽然多了中间层，但可移植性比 MinGW 强。</p>
<p>跨平台属于商业鸿沟，技术上也是一个复杂问题，之所以跨平台这个问题这么难，是因为平台差异导致的，比如可执行文件格式差异，Windows 是 PE 文件，Linux 是 ELF 文件，于是需要分别编译。</p>
</div>
<div class="section" id="msys-msys2">
<h3><a class="reference external" href="http://www.mingw.org/wiki/MSYS">MSYS</a> &amp; <a class="reference external" href="http://www.msys2.org/">MSYS2</a></h3>
<p>MSYS 这个项目，由多年前的 MinGW 团队开始，并成为 Cygwin 的一个分支，一个从来没有跟上 Cygwin 发展的分支，目前已不活跃，如果有选择，请选择 MSYS2。</p>
<p>MSYS2 是 MSYS 的一个升级版，它集成了 pacman 和 <a class="reference external" href="http://mingw-w64.org/">Mingw-w64</a> 的 Cygwin 升级版, 提供了 Bash 等 Linux 环境、版本控制软件（Git/hg）和 MinGW-w64 工具链。
它是由 mingw-builds 团队（也是MinGW-w64工具链的官方包装商）的 Alexey Pavlov 开发的一个项目，密切更新到最新的 Cygwin，使其不会过时。</p>
<p>MSYS2 不完全是基于 MinGW 的，至少其原生工具都是链接到自带的一套特定版本的 Cygwin DLL ，基本上只是用 libalpm 管理 MSYS2、MinGW-w64 和 MinGW 三个不同子系统的软件包。
Cygwin、MSYS 和 Git for Windows（前称 msysgit）里各有一套 Cygwin DLL 而且互不兼容，而 MinGW 那两个子系统都不需要链接到任何版本的 Cygwin DLL。</p>
</div>
<div class="section" id="windows-subsystem-for-linux">
<h3><a class="reference external" href="https://docs.microsoft.com/en-us/windows/wsl/about">Windows Subsystem for Linux</a></h3>
<p>下载安装都很容易，可以在 Windows Store 下载，其中的坑在评论中都已解决。</p>
<ul class="simple">
<li>用户可以使用 Linux 常见工具：grep, sed, awk, Bash, vim, emacs, tmux 等</li>
<li>可以支持很多运行时：Javascript/node.js, Ruby, Python, C/C++, C# &amp; F#, Rust, Go</li>
<li>以及很多 Linux 的服务端软件：sshd, MySQL, Apache, lighttpd</li>
<li>还可以使用包管理器，如 apt-get 等</li>
<li>支持 Linux 和 Windows 程序的双向调用</li>
</ul>
<p>我有安装过 WSL Ubuntu，其性能不高，图形包等并未尝试，相比虚拟机，觉得目前不具太大意义。</p>
</div>
</div>
<div class="section" id="section-2">
<h2>总结</h2>
<p>总的来说，本文讲了 Windows 下用 Linux 的两个例子，再总结了一些 Windows 下 使用 Linux 的方法，整体内容很多。</p>
<p>最后来说，一个更好的方案可能是一台高配 macOS 运行 Parallels Desktop，再其中运行 Windows ;)</p>
<p>感谢阅读。</p>
</div>
</div>
    <footer>
<p class="meta">
  <span class="byline author vcard">
    发布人： <span class="fn">
        Kaffa
    </span>
  </span>
<time datetime="2018-08-14T12:00:00+08:00" pubdate>2018-08-14 周二</time>  <span class="categories">
    <a class='category' href='./category/sui-bi.html'>随笔</a>
  </span>
  <span class="categories">
    <a class="category" href="./tag/sui-bi.html">随笔</a>,    <a class="category" href="./tag/essays.html">Essays</a>,    <a class="category" href="./tag/ji-zhu.html">技术</a>,    <a class="category" href="./tag/technology.html">Technology</a>,    <a class="category" href="./tag/windows.html">Windows</a>,    <a class="category" href="./tag/linux.html">Linux</a>,    <a class="category" href="./tag/jekyll.html">Jekyll</a>,    <a class="category" href="./tag/ruby.html">Ruby</a>,    <a class="category" href="./tag/msys2.html">MSYS2</a>,    <a class="category" href="./tag/vibora.html">Vibora</a>,    <a class="category" href="./tag/cygwin.html">Cygwin</a>,    <a class="category" href="./tag/mingw.html">MinGW</a>,    <a class="category" href="./tag/virtualpc.html">Virtualpc</a>,    <a class="category" href="./tag/vmware.html">VMWare</a>,    <a class="category" href="./tag/docker.html">Docker</a>,    <a class="category" href="./tag/msys.html">MSYS</a>,    <a class="category" href="./tag/msysgit.html">msysgit</a>  </span>
</p><div class="sharing">
</div>    </footer>
    <div id="gitalk-container"></div>
  </article>

</div>

<link rel="stylesheet" href="https://unpkg.com/gitalk/dist/gitalk.css">
<script src="https://unpkg.com/gitalk/dist/gitalk.min.js"></script>
<script>
  var gitalk = new Gitalk({
    clientID: '47c6091c4039fb3df197',
    clientSecret: '8ed206e3b86fb7a90a0dd78d4ed3425d7384b45a',
    repo: 'kaffa.github.io',
    owner: 'kaffa',
    admin: ['kaffa'],
    id: location.pathname.substr(0, 50),
    distractionFreeMode: false
  });
  gitalk.render('gitalk-container');
</script>

<aside class="sidebar">
  <section>
    <h1>最近博文</h1>
    <ul id="recent_posts">
      <li class="post">
          <a href="./hario-mss-1b-mss-1r-16.html">手摇磨豆器-HARIO-MSS-1B-MSS-1R-16-的 12 个零件</a>
      </li>
      <li class="post">
          <a href="./article-39-chapter-iv-of-labor-contract-law-of-China-and-buber-and-drip-bag-coffee.html">公司为什么会选择违法解除劳动合同、包焙儿和挂耳咖啡</a>
      </li>
      <li class="post">
          <a href="./review-2022.html">2022 回顾</a>
      </li>
      <li class="post">
          <a href="./things-in-the-past-half-year-of-2022.html">2022H2半年小记</a>
      </li>
      <li class="post">
          <a href="./alaunch-your-first-productivity-software.html">ALaunch第一个生产力工具</a>
      </li>
    </ul>
  </section>
  <section>

    <h1>分类</h1>
    <ul id="recent_posts">
        <li><a href="./category/ren-wen.html">人文</a></li>
        <li><a href="./category/ri-zhi.html">日志</a></li>
        <li><a href="./category/sui-bi.html">随笔</a></li>
        <li><a href="./category/yue-du.html">阅读</a></li>
        <li><a href="./category/zi-ran.html">自然</a></li>
    </ul>
  </section>

  <section>
  <h1>标签</h1>
    <a href="./tag/sui-bi.html">随笔</a>,    <a href="./tag/essays.html">Essays</a>,    <a href="./tag/ka-pei.html">咖啡</a>,    <a href="./tag/mo-dou-qi.html">磨豆器</a>,    <a href="./tag/hario.html">Hario</a>,    <a href="./tag/ren-sheng.html">人生</a>,    <a href="./tag/life.html">Life</a>,    <a href="./tag/bao-bei-er.html">包焙儿</a>,    <a href="./tag/yue-du.html">阅读</a>,    <a href="./tag/reading.html">Reading</a>,    <a href="./tag/ruan-jian.html">软件</a>,    <a href="./tag/software.html">Software</a>,    <a href="./tag/ji-zhu.html">技术</a>,    <a href="./tag/technology.html">Technology</a>,    <a href="./tag/alaunch.html">ALaunch</a>,    <a href="./tag/productive.html">Productive</a>,    <a href="./tag/bo-ke.html">博客</a>,    <a href="./tag/my-blog.html">My Blog</a>,    <a href="./tag/gitee-pages.html">Gitee Pages</a>,    <a href="./tag/playwright.html">PlayWright</a>,    <a href="./tag/gong-zuo-guan.html">工作观</a>,    <a href="./tag/view-of-work.html">view-of-work</a>,    <a href="./tag/cat.html">Cat</a>,    <a href="./tag/mao.html">猫</a>,    <a href="./tag/wang-wen.html">网文</a>,    <a href="./tag/dian-shi-ju.html">电视剧</a>,    <a href="./tag/ke-bi-bu-lai-en-te.html">科比·布莱恩特</a>,    <a href="./tag/kobe-bryant.html">Kobe Bryant</a>,    <a href="./tag/luo-shan-ji-zao-chen-si-dian.html">洛杉矶早晨四点</a>,    <a href="./tag/los-angeles-morning-4am.html">Los Angeles Morning 4AM</a>,    <a href="./tag/markdown.html">Markdown</a>,    <a href="./tag/markdown-grammar.html">Markdown Grammar</a>,    <a href="./tag/mkdocs.html">MkDocs</a>,    <a href="./tag/hugo.html">Hugo</a>,    <a href="./tag/resume.html">Résumé</a>,    <a href="./tag/fan-qie-gong-zuo-fa.html">番茄工作法</a>,    <a href="./tag/pomodoro-technique.html">Pomodoro Technique</a>,    <a href="./tag/fan-qie-zhong.html">番茄钟</a>,    <a href="./tag/pomodoro-clock.html">Pomodoro Clock</a>,    <a href="./tag/semantic-ui.html">Semantic-UI</a>,    <a href="./tag/nodejs.html">nodejs</a>,    <a href="./tag/pplusplus.html">PPlusPlus</a>,    <a href="./tag/faq.html">FAQ</a>,    <a href="./tag/zeev-suraski.html">Zeev Suraski</a>,    <a href="./tag/internals.html">internals@</a>,    <a href="./tag/php.html">PHP</a>,    <a href="./tag/p.html">P++</a>,    <a href="./tag/rasmus-lerdorf.html">Rasmus Lerdorf</a>,    <a href="./tag/pplusplus-faq.html">PPlusPlus FAQ</a>,    <a href="./tag/microsoft-designer-mouse.html">Microsoft Designer Mouse</a>,    <a href="./tag/linux-distributions.html">Linux Distributions</a>,    <a href="./tag/arch-linux.html">Arch Linux</a>,    <a href="./tag/centos.html">CentOS</a>,    <a href="./tag/debian.html">Debian</a>,    <a href="./tag/elementary-os.html">Elementary OS</a>,    <a href="./tag/fedora.html">Fedora</a>,    <a href="./tag/freebsd.html">FreeBSD</a>,    <a href="./tag/gentoo.html">Gentoo</a>,    <a href="./tag/linux-from-scratch.html">Linux From Scratch</a>,    <a href="./tag/linux-mint.html">Linux Mint</a>,    <a href="./tag/netbsd.html">NetBSD</a>,    <a href="./tag/opensuse.html">openSuse</a>,    <a href="./tag/red-hat-enterprise-linux.html">Red Hat Enterprise Linux</a>,    <a href="./tag/slackware.html">Slackware</a>,    <a href="./tag/ubuntu.html">Ubuntu</a>,    <a href="./tag/restructuretext.html">reStructureText</a>,    <a href="./tag/restructuredtext-grammar.html">reStructuredText Grammar</a>,    <a href="./tag/vscode-extension.html">VSCode Extension</a>,    <a href="./tag/vsce.html">vsce</a>,    <a href="./tag/visual-studio-marketplace.html">Visual Studio Marketplace</a>,    <a href="./tag/macos.html">macOS</a>,    <a href="./tag/mac-os.html">Mac OS</a>,    <a href="./tag/macos-history.html">macOS History</a>,    <a href="./tag/machintosh.html">Machintosh</a>,    <a href="./tag/beos.html">BeOS</a>,    <a href="./tag/next.html">NeXT</a>,    <a href="./tag/openstep.html">OPENSTEP</a>,    <a href="./tag/mach.html">Mach</a>,    <a href="./tag/ren-wen.html">人文</a>,    <a href="./tag/humanity.html">Humanity</a>,    <a href="./tag/luo-ji-xue.html">逻辑学</a>,    <a href="./tag/logic.html">Logic</a>,    <a href="./tag/ke-ji-suan-xing.html">可计算性</a>,    <a href="./tag/shi-wu.html">事物</a>,    <a href="./tag/shi-jian.html">事件</a>,    <a href="./tag/shi-shi.html">事实</a>,    <a href="./tag/guan-nian.html">观念</a>,    <a href="./tag/ming-ti.html">命题</a>,    <a href="./tag/duan-yan.html">断言</a>,    <a href="./tag/yan-yi.html">演绎</a>,    <a href="./tag/gui-na.html">归纳</a>,    <a href="./tag/san-duan-lun.html">三段论</a>,    <a href="./tag/tong-yi-lu.html">同一律</a>,    <a href="./tag/pai-zhong-lu.html">排中律</a>,    <a href="./tag/yin-guo-lu.html">因果律</a>,    <a href="./tag/mao-dun-lu.html">矛盾律</a>,    <a href="./tag/zi-ran.html">自然</a>,    <a href="./tag/natural-science.html">Natural Science</a>,    <a href="./tag/xiong-ji-diao.html">胸棘鲷</a>,    <a href="./tag/orange-roughy.html">Orange Roughy</a>,    <a href="./tag/chang-shou-yu.html">长寿鱼</a>,    <a href="./tag/hua-shi-ren-lei-xue.html">化石人类学</a>,    <a href="./tag/gu-ren-lei-xue.html">古人类学</a>,    <a href="./tag/zhi-ren.html">智人</a>,    <a href="./tag/homo-sapiens.html">Homo sapiens</a>,    <a href="./tag/ni-an-de-te-ren.html">尼安德特人</a>,    <a href="./tag/homo.html">Homo</a>,    <a href="./tag/neanderthals.html">Neanderthals</a>,    <a href="./tag/sheng-zhi-ge-chi.html">生殖隔离</a>,    <a href="./tag/ji-yin-ce-xu.html">基因测序</a>,    <a href="./tag/ji-suan-ji-ke-xue.html">计算机科学</a>,    <a href="./tag/computer-science.html">Computer Science</a>,    <a href="./tag/dian-zi-gong-cheng.html">电子工程</a>,    <a href="./tag/electronic-engineering.html">Electronic Engineering</a>,    <a href="./tag/ruan-jian-gong-cheng-xue.html">软件工程学</a>,    <a href="./tag/software-engineering.html">Software Engineering</a>,    <a href="./tag/xin-xi-ji-zhu.html">信息技术</a>,    <a href="./tag/information-technology.html">Information Technology</a>,    <a href="./tag/geetest.html">GeeTest</a>,    <a href="./tag/windows.html">Windows</a>,    <a href="./tag/linux.html">Linux</a>,    <a href="./tag/jekyll.html">Jekyll</a>,    <a href="./tag/ruby.html">Ruby</a>,    <a href="./tag/msys2.html">MSYS2</a>,    <a href="./tag/vibora.html">Vibora</a>,    <a href="./tag/cygwin.html">Cygwin</a>,    <a href="./tag/mingw.html">MinGW</a>,    <a href="./tag/virtualpc.html">Virtualpc</a>,    <a href="./tag/vmware.html">VMWare</a>,    <a href="./tag/docker.html">Docker</a>,    <a href="./tag/msys.html">MSYS</a>,    <a href="./tag/msysgit.html">msysgit</a>,    <a href="./tag/pelican.html">Pelican</a>,    <a href="./tag/gitalk.html">Gitalk</a>,    <a href="./tag/gitment.html">Gitment</a>,    <a href="./tag/pelican-octopress-theme.html">Pelican Octopress Theme</a>,    <a href="./tag/pelican-octopress-theme-cn.html">pelican-octopress-theme-cn</a>,    <a href="./tag/node.html">Node</a>,    <a href="./tag/path.html">Path</a>,    <a href="./tag/psychology.html">Psychology</a>,    <a href="./tag/philosophy.html">Philosophy</a>,    <a href="./tag/nwjs.html">NW.js</a>,    <a href="./tag/electron.html">Electron</a>,    <a href="./tag/qrcode.html">QRCode</a>,    <a href="./tag/text-qrcode.html">Text QRCode</a>,    <a href="./tag/wechaty.html">Wechaty</a>,    <a href="./tag/open-source.html">Open Source</a>,    <a href="./tag/vscode.html">VSCode</a>,    <a href="./tag/linux-kernel.html">Linux Kernel</a>,    <a href="./tag/data.html">Data</a>,    <a href="./tag/information.html">Information</a>,    <a href="./tag/restructuredtext.html">reStructuredText</a>,    <a href="./tag/rst.html">rst</a>,    <a href="./tag/blog.html">Blog</a>,    <a href="./tag/zi-ding-yi-yu-ming.html">自定义域名</a>,    <a href="./tag/custom-domain.html">Custom Domain</a>,    <a href="./tag/github-pages.html">GitHub Pages</a>,    <a href="./tag/cname.html">CNAME</a>,    <a href="./tag/ji-zhu-zhi-shi-fen-lei.html">技术知识分类</a>,    <a href="./tag/technology-category.html">Technology Category</a>,    <a href="./tag/wen-ti-jie-jue.html">问题解决</a>,    <a href="./tag/problem-solving.html">Problem Solving</a>,    <a href="./tag/biao-ji-yu-yan.html">标记语言</a>,    <a href="./tag/octopress.html">octopress</a>,    <a href="./tag/asciidoc.html">AsciiDoc</a>  </section>


    <section>
        <h1>社区</h1>
        <ul>
            <li><a href="https://github.com/kaffa" target="_blank">My GitHub</a></li>
        </ul>
    </section>
    <section>
        <h1>链接</h1>
        <ul>
            <li><a href="http://paulgraham.com" target="_blank">Paul Graham</a></li>
            <li><a href="https://gvanrossum.github.io/" target="_blank">Guido van Rossum</a></li>
            <li><a href="https://kaffa.im" target="_blank">Kaffa</a></li>
            <li><a href="https://coffees.app" target="_blank">Coffee's</a></li>
            <li><a href="https://lundao.pub/" target="_blank">论道</a></li>
        </ul>
    </section>

</aside>    </div>
  </div>
  <footer role="contentinfo"><p>
    版权所有 &copy;  2018&ndash;2023  Kaffa &mdash;
  <span class="credit">自豪地采用 <a href="http://getpelican.com">Pelican</a> 技术</span>
</p></footer>
  <script src="./theme/js/modernizr-2.0.js"></script>
  <script src="./theme/js/ender.js"></script>
  <script src="./theme/js/octopress.js" type="text/javascript"></script>
  
</body>
</html>